package com.company2021.meituan7;

import java.util.Scanner;

/**
 * TODO
 *
 * @author lefly
 * @version 1.0
 * @classname Main2
 * @description
 * @date 2021/3/11 下午3:53
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        int p = sc.nextInt();
        int q = sc.nextInt();
        // 地图
        char[][] map = new char[m][n];
        // 初始位置
        int initI = 0,initJ = 0;
        for (int i = 0; i < m ; i++) {
            String input = sc.next();
            for (int j = 0; j < n ; j++) {
                char []c = input.toCharArray();
                if(c[j]== 'S'){
                    initI = i;
                    initJ = j;
                }
                map[i][j] = c[j];
            }
        }
        char[] array = sc.next().toCharArray();
        int res = helper(map,m,n,p,q,initI,initJ,array);
        System.out.println(res);

    }

    private static int helper(char[][] map,int m,int n,int p,int q,int initX,int initY,char[] op){
        int score = 0;
        int len = op.length;
        for (int i = 0; i < len; i++) {
            char d = op[i];
            int[] direction = getDirection(d);
            int tX = initX,ty = initY;
            initX += direction[0];
            initY += direction[1];
            if(initX < 0 || initX >= m || initY < 0 || initY >= n || map[initX][initY] == '#'){
                initX = tX;
                initY = ty;
                continue;
            }
            if(map[initX][initY] == 'O'){
                score += p;
            }
            if(map[initX][initY] == 'X'){
                score -= q;
            }
            map[initX][initY] = '+';
        }


        return score;
    }

    private static int[] getDirection(char d) {
        int [] direction = new int[2];
        switch (d){
            case 'W':
                direction[0] = -1;
                direction[1] = 0;
                break;
            case 'A':
                direction[0] = 0;
                direction[1] = -1;
                break;
            case 'S':
                direction[0] = 1;
                direction[1] = 0;
                break;
            default:
                direction[0] = 0;
                direction[1] = 1;
        }
        return direction;
    }


}
